import { Controller } from '@nestjs/common';
import { ArticleCategoryService } from './article-category.service';
import { ApiBearerAuth, ApiExcludeEndpoint, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Body, Delete, Get, Param, Post, Put } from '@nestjs/common';
import { CreateArticleCategoryDto } from './article-category.dto';
import { Public } from '~/modules/auth/decorators/public.decorator';
import { AuthUser } from '~/modules/auth/decorators/auth-user.decorator';
import { AuthTenant } from '~/modules/tenant/tenant.decorator';
import { ArticleCategoryEntity } from './article-category.entity';
import { ModuleSwaggerTags } from '~/constants/modules.constant';

@ApiTags(ModuleSwaggerTags.ARTICLE)
@ApiBearerAuth()
@Controller('cms/article/category')
export class ArticleCategoryController {
  constructor(private readonly articleCategoryService: ArticleCategoryService) {}

	@ApiExcludeEndpoint()
  @Public()
  @Get()
  @ApiOperation({ summary: '查询所有分类 - 待完成' })
  async findAll(
    @AuthUser() user: IAuthUser,
    @AuthTenant() tenant: IAuthTenant
  ): Promise<ArticleCategoryEntity[]> {
    if (user?.isSuperAdmin) {
      return await this.articleCategoryService.findAllByTenantId();
    }

    return this.articleCategoryService.findAllByTenantId(tenant?.id);
  }

	@ApiExcludeEndpoint()
  @Get(':id')
  @ApiOperation({ summary: '查询分类 - 待完成' })
  findOne(@Param('id') id: string) {
    return this.articleCategoryService.findOne(Number(id));
  }

  @Post()
  @ApiOperation({ summary: '创建分类' })
  create(@Body() dto: CreateArticleCategoryDto) {
    return this.articleCategoryService.create(dto);
  }

	@ApiExcludeEndpoint()
  @Put(':id')
  @ApiOperation({ summary: '更新分类 - 待完成' })
  update(@Param('id') id: string, @Body() dto: CreateArticleCategoryDto) {
    return this.articleCategoryService.update(Number(id), dto);
  }

	@ApiExcludeEndpoint()
  @Delete(':id')
  @ApiOperation({ summary: '删除分类 - 待完成' })
  remove(@Param('id') id: string) {
    return this.articleCategoryService.remove(Number(id));
  }
}
